package com.banciyuan.bcywebview.base.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;

public class CircleFilterDialog extends Dialog {
    public CircleFilterDialog(Context context) {
        super(context);
    }

    public CircleFilterDialog(Context context, int theme) {
        super(context, theme);
    }

    protected CircleFilterDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static class Builder {
        private Context context;
        private View viewTagArrow, viewWorkArrow;
        private TextView tvDiscoverTag, tvDiscoverWork;
        private View.OnClickListener tagClickListener, workClickListener;
        private int default_type = 0;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setTagClickListener(View.OnClickListener tagClickListener) {
            this.tagClickListener = tagClickListener;
            return this;
        }

        public Builder setWorkClickListener(View.OnClickListener workClickListener) {
            this.workClickListener = workClickListener;
            return this;
        }

        public Builder setDefault_type(int default_type) {
            this.default_type = default_type;
            return this;
        }

        public CircleFilterDialog create() {
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.group_type_selector_dialog_circle_layout, null);
            viewTagArrow = view.findViewById(R.id.iv_tag_arrow);
            viewWorkArrow = view.findViewById(R.id.iv_work_arrow);
            tvDiscoverTag = (TextView) view.findViewById(R.id.tv_discover_tag);
            tvDiscoverWork = (TextView) view.findViewById(R.id.tv_discover_work);
            switch (default_type) {
                case 0:
                    viewTagSelected();
                    break;
                case 1:
                    viewWorkSelected();
                    break;

            }
            final CircleFilterDialog circleFilterDialog = new CircleFilterDialog(context, R.style.BestAlphaDialog);
            view.findViewById(R.id.view_discover_tag).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    viewTagSelected();
                    if (null != tagClickListener)
                        tagClickListener.onClick(v);
                    circleFilterDialog.dismiss();
                }
            });
            view.findViewById(R.id.view_discover_work).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    viewWorkSelected();
                    if (null != workClickListener)
                        workClickListener.onClick(v);
                    circleFilterDialog.dismiss();
                }
            });

            view.findViewById(R.id.dialoglayout).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    circleFilterDialog.dismiss();
                }
            });
            circleFilterDialog.setContentView(view);
            return circleFilterDialog;
        }

        private void viewWorkSelected() {
            viewTagArrow.setVisibility(View.GONE);
            viewWorkArrow.setVisibility(View.VISIBLE);
            tvDiscoverTag.setTextColor(context.getResources().getColor(R.color.mine_textcolor));
            tvDiscoverWork.setTextColor(context.getResources().getColor(R.color.pink));
            tvDiscoverTag.setTypeface(null, Typeface.NORMAL);
            tvDiscoverWork.setTypeface(null, Typeface.BOLD);
        }

        private void viewTagSelected() {
            viewTagArrow.setVisibility(View.VISIBLE);
            viewWorkArrow.setVisibility(View.GONE);
            tvDiscoverTag.setTextColor(context.getResources().getColor(R.color.pink));
            tvDiscoverWork.setTextColor(context.getResources().getColor(R.color.mine_textcolor));
            tvDiscoverTag.setTypeface(null, Typeface.BOLD);
            tvDiscoverWork.setTypeface(null, Typeface.NORMAL);
        }
    }

}
